<template>
  <!-- 卡片视图区 -->
  <el-card>
    <el-row :gutter="25">
      <el-col :span="7">
        <!-- 搜索添加-->
        <el-input
          placeholder="请输入"
          v-model.lazy="queryInfo.searchId"

          @change="getPeopleList"
        >
        </el-input> 
      </el-col>
    <el-col :span="4">
        <el-button type="primary" @click="dialogAddVisible = true"
          >添加</el-button
        >
      </el-col>
    </el-row>
    <!-- 列表 -->
    <el-table
      :data="peopleList"
      border
      stripe
      v-loading="isLoading"
      element-loading-background="rgba(255, 255, 255, .5)"
      element-loading-text="加载中，请稍后..."
      element-loading-spinner="el-icon-loading"
    >
      <el-table-column label="组ID" prop="ZId"></el-table-column>
      <el-table-column label="组名称" prop="ZName"></el-table-column>
      <el-table-column label="分项ID" prop="FxId"></el-table-column>
      <el-table-column label="分项目名称" prop="FxName"></el-table-column>
   </el-table>
     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.page"
      :page-sizes="[15, 100]"
      :page-size="queryInfo.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </el-card>

  <el-dialog title="添加" v-model="dialogAddVisible" width="50%">
    <el-form
      :model="addForm"
      :rules="addFormRules"
      ref="addFormRef"
      label-width="100px"
    >
      <el-form-item label="组ID" prop="ZId">
        <el-input v-model="addForm.ZId"></el-input>
      </el-form-item>
      <el-form-item label="组名称" prop="ZName">
        <el-input v-model="addForm.ZName"></el-input>
      </el-form-item>
      <el-form-item label="分项ID" prop="FxId">
        <el-input v-model="addForm.FxId"></el-input>
      </el-form-item>
      <el-form-item label="分项名称" prop="FxName">
        <el-input v-model="addForm.FxName"></el-input>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="addPeople()">确 定</el-button>
    <el-button @click="dialogAddVisible = false">取 消</el-button>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      isLoading: false,
      dialogAddVisible: false,
      dialogEditVisible: false,
      queryInfo: {
        searchId: "",
        page: 1,
        limit: 15,
        
      },
      
     peopleList: [], // 
      total: 0, 
       addForm: {
        ZId: "",
        ZName: "",
        FxId: "",
        FxName: "",
      },
    };
  }, 

  created() {
    this.getPeopleList();
  },
  methods: {
    async getPeopleList() {
      this.isLoading = true;
      // 调用post请求
      //console.log(this.studentList)
      const { data: res } = await this.$http.get("system/apis/common", {
        params: this.queryInfo,
      });
      if (res.code != 20000) {
        this.$message.error("加载用户列表失败");
        this.isLoading = false;
      }
      this.peopleList = res.data.value; // 将返回数据赋值
      this.total = res.data.total; // 总个数
      this.isLoading = false;
    },
    // 监听pageSize改变的事件
    handleSizeChange(newLimit) {
      this.queryInfo.limit = newLimit;
      this.getPeopleList(); // 数据发生改变重新申请数据
    },
    // 监听pageNum改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      this.getPeopleList(); // 数据发生改变重新申请数据
    },
     addPeople() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return;
        // 发起请求
        const { data: res } = await this.$http.post(
          "/system/apis/common",
          this.addForm
        );
        if (res.code == 20000) {
          this.getPeopleList();
          this.dialogAddVisible = false;
          return this.$message.success("添加成功");
        }
        this.$message.error("添加失败");
      });
    },
  },
};
</script>
<style>
</style>